/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.ui.rich.prep.view.command;

import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;

import br.ufmg.dees.insane.commons.command.Command;
import br.ufmg.dees.insane.ui.rich.prep.view.InterfacePrep;

/** The redraw command.
 *
 * @author Ferreira, Reginaldo & Pitangueira, Roque
 * @since november 2006
 */
public class RenameViewCommand implements Command {
	
	private InterfacePrep parent;
    
//*****************************************************************************
	
    /** Constructor method */
    public RenameViewCommand(JInternalFrame parent) {
    	this.parent = (InterfacePrep)parent;
    }
    
//*****************************************************************************
	
	/** The execute method. */
    public void execute() {
    	String old_name = parent.getTitle();
    	int pos = old_name.indexOf("-");
    	String temp = old_name.substring(pos+2);
    	
        String txt = JOptionPane.showInputDialog(parent, "Rename < " + temp + " >  to:", "Rename the View", JOptionPane.QUESTION_MESSAGE);
       if (txt != null)
        {
    	   String new_name = parent.getModel().getName() + " - " + txt;
    	   parent.setTitle(new_name);
    	   parent.getDesktopFrame().getDesktopTextArea().addText("The view  [ " + old_name + " ]  was renamed to: " + new_name);
        }
       else
    	   parent.getDesktopFrame().getDesktopTextArea().addText("Rename view command was canceled!");
	}
	
//*****************************************************************************
	
	/** Impossible to redo - Not implemented */
    public void redo() {
    }
    
//*****************************************************************************
	
	/** Impossible to undo - Not implemented */
    public void undo() {
    }
    
//*****************************************************************************
}

